var utils = require('../../utils/util.js')
var app = getApp()
const domainUrl = app.globalData.domainUrl

Page({
  data: {
    userInfo: {},
    path:'',
    isLogin: 0
  },
  onLoad: function (options) {
    utils.login(this.route);
    this.setData({
      path:'./../my/feedback/feedback'
    })
    //var that = this;
    //调用应用实例的方法获取全局数据
    // app.getUserInfo(function (userInfo) {
    //   console.log(userInfo);
    //   //更新数据
    //   that.setData({
    //     userInfo: userInfo
    //   })
    // })
  },
  onShareAppMessage: function () {
    // 用户点击右上角分享
    return {
      title: '', // 分享标题
      desc: '', // 分享描述
      path: '' // 分享路径
    }
  },
  showMyWord: function () {
    wx.showModal({
      title: '提示',
      content: '此功能暂未开放，敬请期待！',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        }
      }
    })
  },
  naviToReport: function () {
    wx.navigateTo({
      url: '../report/index',
    })
  },
  showClause: function () {
    wx.navigateTo({
      url: './clause/clause',
      success: function (res) {
        // success
      }
    })
  },
  showBag: function () {
    wx.navigateTo({
      url: './mycard/mycard',
      success: function (res) {
        // success
      }
    })
  },
  showPintu: function() {
    wx.navigateTo({
      url: '../puzzle/index',
    })
  },
  showHelp: function () {
    wx.navigateTo({
      url: './help/help',
      success: function (res) {
        // success
      }
    })
  },
  showFeedback: function () {
    var that = this
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo)
              app.globalData.userInfo = res.userInfo
              wx.navigateTo({
                url: './feedback/feedback',
                success: function (res) {
                  // success
                }
              })
            }
          })
        } else {
          var route = that.data.path
          wx.navigateTo({
            url: './../login/login?type=1&path='+route,
            success: function (res) {
              // success
            }
          })
        }
      }
    })
  },
  getUserInfo: function() {
    wx.navigateTo({
      url: './../login/login',
      success: function (res) {
        // success
      }
    })
  },
  bindGetUserInfo: function () {
    var that = this
    wx.getUserInfo({
      success: function (res) {
        console.log("bindGetUserInfo userInfo:" + res)
        app.globalData.userInfo = res.userInfo;
        console.log(that.data.path)
        that.setData({
          isLogin: 1
        });
        console.log(res.userInfo)
        wx.request({
          url: domainUrl + 'shuihuCardSaveUser',
          method: 'POST',
          data: {
            nickName: res.userInfo.nickName,
            picUrl: res.userInfo.avatarUrl,
            userId: wx.getStorageSync('my_openid'),
            gender: res.userInfo.gender,
            province: res.userInfo.province,
            city: res.userInfo.city,
            country: res.userInfo.country,
            language: res.userInfo.language
          }
        })
      }
    })
  },
  logout: function () {
    this.setData({
      isLogin: 0
    });
  },
  onShow: function () {
    console.log("显示图片")
    var that = this;
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          that.setData({
            isLogin: 1
          })
        } else {
          that.setData({
            isLogin: 0
          })
        }
      }
    })
  },
  openSetting: function() { wx.openSetting() }
})